package com.sky.mapper;

import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {
    /**
     * 获取菜品关联套餐的数量
     *
     * @param ids
     * @return
     */
    long selectCountByDishIds(@Param("dishIds") List<Long> ids);

    /**
     * 保存菜品套餐信息
     *
     * @param setmealDishes
     */
    void saveSetmealDish(@Param("setmealDishes") List<SetmealDish> setmealDishes);

    /**
     * 根据套餐ID删除关联菜品
     *
     * @param id
     */
    @Delete("DELETE FROM setmeal_dish WHERE setmeal_id = #{id}")
    void deleteBySetmealId(Long id);

    /**
     * 根据套餐id查询包含的菜品列表
     *
     * @param id
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{id}")
    List<DishItemVO> getAllDishById(Long id);

    /**
     * 删除套餐下的菜品
     *
     * @param ids
     */
    void deleteByIds(@Param("ids") List<Long> ids);

    /**
     * 根据套餐id查询关联菜品
     * @param id
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> selectSetmealDish(Long id);
}
